package com.docking.heylo.web.controller;

import com.docking.heylo.dao.entity.SysRole;
import com.docking.heylo.service.ISysRoleService;
import com.docking.heylo.web.dto.SysRoleDto;
import com.docking.heylo.web.utils.ResultUtil;
import com.docking.heylo.web.vo.BaseVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/***
 * 系统角色控制器
 *
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private ISysRoleService roleService;

    /***
     * 新建角色信息
     *
     * @return
     */
    @RequestMapping("/saveRole")
    public BaseVo saveRole(@RequestBody @Validated(SysRoleDto.Save.class) SysRoleDto role){
        roleService.saveRole(role);
        return ResultUtil.success("新增角色成功");
    }

    /***
     * 角色列表
     *
     * @return
     */
    @RequestMapping("/roleList")
    public BaseVo roleList(@RequestBody SysRoleDto roleDto){
        PageInfo<Map<String, Object>> roleVos = roleService.roleList(roleDto);
        return ResultUtil.success("成功", roleVos);
    }

    /***
     * 查看角色信息
     *
     * @param roleDto
     * @return
     */
    @RequestMapping("/roleInfo")
    public BaseVo roleInfo(@RequestBody @Validated(SysRoleDto.View.class) SysRoleDto roleDto){
        SysRole role = roleService.roleInfo(roleDto.getId());
        return ResultUtil.success("成功",role);
    }

    /***
     * 修改角色信息
     *
     * @param roleDto
     * @return
     */
    @RequestMapping("/editRole")
    public BaseVo editRole(@RequestBody @Validated(SysRoleDto.Edit.class) SysRoleDto roleDto){
        roleService.editRole(roleDto);
        return ResultUtil.success("修改角色信息成功");
    }

    /***
     * 删除角色信息
     *
     * @param roleDto
     * @return
     */
    @RequestMapping("/delRole")
    public BaseVo delRole(@RequestBody @Validated(SysRoleDto.View.class) SysRoleDto roleDto){
        roleService.delRole(roleDto.getId());
        return ResultUtil.success("删除角色成功");
    }












}
